###########################################
# DESCRIBE RESISTANCE MEMBERSHIP BY GROUP #
###########################################
# Author: Kasia Nalewajko
# First created: 13 December 2023
# Replicated: 29 May 2024

rm(list = ls())

# LOAD PACKAGES -----------------------------------------------------------

if (!require("dplyr")) install.packages("dplyr")
if (!require("tidyr")) install.packages("tidyr")
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("sf")) install.packages("sf")
if (!require("raster")) install.packages("raster")
if (!require("Hmisc")) install.packages("Hmisc")

# LOAD DATA ---------------------------------------------------------------

load("./00 SUBMITTED/00 APSR final/04 replication_files/01 data/resisters_all.Rda")

# CLEAN DATA ---------------------------------------------------------------

temp <- all_resisters %>% 
  dplyr::mutate(French = ifelse(id_naissance_pays_intitule == "France", 1, 0)) %>% 
  dplyr::select(French, jew_0.99, FFI, FFC, FFL, RIF) 

table <- temp %>% 
  group_by(French, jew_0.99) %>% 
  summarise(across(FFI:RIF,
                   ~sum(.))) %>% 
  gather(key = "group", value = "members", -c(French, jew_0.99))

labels <- as.character(unlist(table$members))

# labels <- c("20713","232070","13891","56885","36095","27540","2192","18071","6951","75677")
# labels <- c("FFI foreigners","FFI French","FFC foreigners","FFC French","FFL foreigners","FFL French","RIF foreigners","RIF French","DIR foreigners","DIR French")

# PLOT ---------------------------------------------------------------

table %>% 
  ggplot(aes(x = factor(group, levels = c("FFI", "FFC", "FFL", "RIF")), 
             y = as.numeric(members))) +
  geom_col(aes(fill = as.factor(jew_0.99), group = as.factor(French)), position = position_dodge(0.9)) +
  labs(title = "",
       subtitle = "",
       fill = "Jew",
       x = "Type of La Résistance group",
       y = "Number members") +
  scale_fill_viridis_d(option = "inferno",
                       begin = 0.2, end = 0.85) +
  theme_bw()

# SAVE ---------------------------------------------------------------

ggsave(
  "3_resisters_group_all.png",
  plot = last_plot(),
  path = "./00 SUBMITTED/00 APSR final/01 main_text/figures",
  width = 17,
  height = 10,
  units = "cm",
  dpi = 300
)



